/*********************************************************************
 * 						computer graphics
 * 							exercise 4
 * 					shaham fridenberg 039421268
 *                    danielle barda 304954654
 ********************************************************************/

public class Wall {
	Vector [] points;
	double angleLimit;
	
	public Wall(Vector v1, Vector v2, Vector v3, Vector v4, double angleLimit)
	{
		points = new Vector[4];
		points[0] = v1;
		points[1] = v2;
		points[2] = v3;
		points[3] = v4;
		this.angleLimit = angleLimit;
	}
	
	public boolean isTooClose(Vector eye)
	{
		Vector t1 = eye.minus(points[0]);
		Vector t2 = eye.minus(points[1]);
		Vector t3 = eye.minus(points[2]);
		Vector t4 = eye.minus(points[3]);
		
		double sumAngles = calcAngle(t1, t2) + calcAngle(t2, t3) + calcAngle(t3, t4)
						 + calcAngle(t4, t1);
				
		if(sumAngles > angleLimit)
			return true;
		return false;
	}
	
	public double calcAngle(Vector v1, Vector v2)
	{
		double t = (v1.mul(v2)) / (v1.len() * v2.len());
		return Math.acos(t)*180.0/3.14159;
	}
	
	public void printWall()
	{
		System.out.println("wall:");
		for(int i=0; i<4; i++)
			points[i].printVector();
		System.out.println();
	}
}
